package com.yswl.yeeduo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yswl.yeeduo.R;

public class GuidePointView extends LinearLayout {
	ImageView[] indicator_imgs;
	private int pointCount;

	public GuidePointView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView();
	}

	public GuidePointView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	public GuidePointView(Context context, int picCount) {
		super(context);
		initView();
	}

	private void initView(){
		this.setOrientation(LinearLayout.HORIZONTAL);
		this.setGravity(Gravity.CENTER);
	}
	
	public void initPoint(int picCount) {
		pointCount = picCount;
		if (picCount <= 1) {
			return;
		}
		// 进度点
		indicator_imgs = new ImageView[picCount];
		for (int i = 0; i < picCount; i++) {
			indicator_imgs[i] = new ImageView(getContext());
			LinearLayout.LayoutParams params_linear = new LinearLayout.LayoutParams(10, 10);
			params_linear.setMargins(7, 10, 7, 10);
			indicator_imgs[i].setLayoutParams(params_linear);
			if (i == 0) {
				// 初始化第一个为选中状态
				indicator_imgs[i].setBackgroundResource(R.drawable.indicator_focused);
			} else {
				indicator_imgs[i].setBackgroundResource(R.drawable.indicator);
			}
			this.addView(indicator_imgs[i]);
		}
	}

	public void setCurrPoint(int currPosition) {
		// 改变所有导航的背景图片为：未选中
		for (int i = 0; i < pointCount; i++) {
			indicator_imgs[i].setBackgroundResource(R.drawable.indicator);
		}
		// 改变当前背景图片为：选中
		indicator_imgs[currPosition % pointCount].setBackgroundResource(R.drawable.indicator_focused);
	}

}
